package com.zxm.web.controller.message;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @Author silence.Z
 * @Date 2022/8/29 13:15
 * @PackageName:com.zxm.web.controller.message
 * @ClassName: SseConnection
 * @Description: TODO
 * @Version 1.0
 */
@RestController
public class TestSseController {

	@Autowired
	private ApplicationEventPublisher applicationEventPublisher;


	@GetMapping("/test1/{userId}/{message}")
	public ResponseEntity test(@PathVariable("userId") String userId, @PathVariable("message") String message) {
		SseEvent<String> sseEvent = new SseEvent<>(this);
		sseEvent.setCode(200);
		sseEvent.setMsg(message);
		sseEvent.setUserId(userId);
		applicationEventPublisher.publishEvent(sseEvent);
		return ResponseEntity.ok().build();
	}

}

